package com.vogtec.fota.quartz;

import lombok.extern.slf4j.Slf4j;
import org.quartz.*;
import org.quartz.impl.StdSchedulerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Component;

import java.sql.Timestamp;

/**
 * Created by wei on 2017/7/24.
 */
@Component("startSchedule")
//@Scope("proto
// type")
@Slf4j
public class StartSchedule {

    public void main(Timestamp sta, Integer id) throws SchedulerException{

        log.info("***** in quartz.StartSchedule ***** : sta : [{}] , id : [{}]",sta,id);

        SchedulerFactory schedulerFactory = new StdSchedulerFactory();
        Scheduler scheduler = schedulerFactory.getScheduler();

//        JobDetail jobDetail = ApplicationContextProvider.getBean("jobDetail",JobDetail.class);
        JobDetail jobDetail = new JobDetail("jobDetail-" + id, Scheduler.DEFAULT_GROUP, StartJob.class);
        jobDetail.getJobDataMap().put("id",id.toString());

        SimpleTrigger simpleTrigger = new SimpleTrigger("simpleTrigger-" + id, Scheduler.DEFAULT_GROUP);
        simpleTrigger.setStartTime(sta);

        scheduler.scheduleJob(jobDetail,simpleTrigger);

        scheduler.start();
    }
}
